package com.siberhus.tdfl.processor;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.siberhus.tdfl.Employee;
import com.siberhus.tdfl.FieldDataException;
import com.siberhus.tdfl.processor.AbstractDataFileProcessor;
import com.siberhus.tdfl.transform.FieldSet;

public class EmployeeDfp extends AbstractDataFileProcessor<Employee>{

	private Log logger = LogFactory.getLog(EmployeeDfp.class);

	
	@Override
	public Employee mapLine(FieldSet fs, FieldDataException fde)
			throws Exception {
		Employee item = new Employee();
		item.setId(fs.read(Long.class, "Id"));
		item.setFullName(fs.readString("Fullname"));
		item.setEmail(fs.readString("Email"));
		item.setBirthdate(fs.read(java.sql.Date.class, "Birthdate"));
		item.setSalary(fs.read(Integer.class, "Salary"));
		return item;
	}
	
	@Override
	public void validateItem(Employee item, FieldDataException fde)
			throws Exception {
		
	}
	
	@Override
	public void processItem(Employee item) throws Exception {
		logger.info("Saving 'employee' data-> "+item);
	}
	
	@Override
	public void onItemError(Employee item, Exception exception) {
		logger.warn("Item error -> "+item);
	}
	
	
}
